//Date: 2024-12-04 10:23:04
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
inline int rd() {
    int s=0,m=0;char ch=getchar();
    while(!isdigit(ch)) {if(ch=='-')m=1;ch=getchar();}
    while( isdigit(ch)) s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
    return m?-s:s;
}
bool MBE;
namespace SOLVER {
int n,m,a[400005],b[400005],vis[400005],sz,sum;
struct Node {int s0,s1;ull s2;} t[(1<<20)+5];
#define ls (p<<1)
#define rs (p<<1|1)
#define mid ((l+r)>>1)
inline Node pushup(Node pl,Node pr) {return {pl.s0+pr.s0,pl.s1+pr.s1,pl.s2+pr.s2+pl.s0*pr.s1};}
void upd(int p,int l,int r,int x,Node v) {
    if(l==r) {t[p].s0+=v.s0,t[p].s1+=v.s1,t[p].s2+=v.s2;return;}
    x<=mid?upd(ls,l,mid,x,v):upd(rs,mid+1,r,x,v);
    t[p]=pushup(t[ls],t[rs]);
}
int qrypre(int p,int l,int r,int k,int& x) {
    if(l==r) {x=l;return t[p].s1;}
    return k<=t[ls].s0?qrypre(ls,l,mid,k,x):qrypre(rs,mid+1,r,k-t[ls].s0,x)+t[ls].s1;
}
int qrysuf(int p,int l,int r,int k,int& x) {
    if(l==r) {x=l;return t[p].s1;}
    return k<=t[rs].s0?qrysuf(rs,mid+1,r,k,x):qrysuf(ls,l,mid,k-t[rs].s0,x)+t[rs].s1;
}
Node query(int p,int l,int r,int L,int R) {
    if(L<=l&&r<=R) return t[p];
    if(R<=mid) return query(ls,l,mid,L,R);
    if(L>mid) return query(rs,mid+1,r,L,R);
    return pushup(query(ls,l,mid,L,R),query(rs,mid+1,r,L,R));
}
ull ask(int l,int r) {
    if(l>r) return 0;
    ull sum=0;int p1=0,p2=0,p3=0,p4=0;
    sum+=qrypre(1,1,m,r+1,p2)*(r-l+1);
    if(l+2<=r+1) qrypre(1,1,m,l+2,p1),sum-=query(1,1,m,p1,p2).s2;
    qrysuf(1,1,m,r,p3);qrysuf(1,1,m,l-1,p4);
    sum-=query(1,1,m,p3,m).s2-query(1,1,m,p4,m).s2;
    return sum;
}
void MAIN() {
    cin>>n;for(int i=1;i<=n;i++) a[i]=b[i]=rd();
    sort(b+1,b+n+1);m=unique(b+1,b+n+1)-b-1;b[++m]=1e12+1;
    for(int i=1;i<=n;i++) {
        a[i]=lower_bound(b+1,b+m+1,a[i])-b;
        if(vis[a[i]]) {//del
            vis[a[i]]=0,sz--,sum-=b[a[i]];
            upd(1,1,m,a[i],{-1,-b[a[i]],-(ull)b[a[i]]});
        }
        else {//add
            vis[a[i]]=1,sz++,sum+=b[a[i]];
            upd(1,1,m,a[i],{+1,+b[a[i]],+(ull)b[a[i]]});
        }
        if(sz<=1) {puts("0");continue;}
        int pos=-1,res,Mn=qrypre(1,1,m,1,res);ull ans=sum-Mn-Mn;
        for(int l=1,r=sz/2;l<=r;) {
            if(qrypre(1,1,m,mid+1,res)>qrysuf(1,1,m,mid,res)) pos=mid,l=mid+1;
            else r=mid-1; 
        }
        if(pos==-1) {printf("%llu\n",ans);continue;}
        int l=pos,r=sz-l-1;ull sum=ask(1,sz-2)-ask(l+1,r-1);
        printf("%llu\n",ans-sum);
    }
}
}
bool MED;
signed main() {
    freopen("kte.in","r",stdin);freopen("kte.out","w",stdout);
    for(int tt=1;tt;tt--) SOLVER::MAIN();
    cerr<<(&MBE-&MED)/1024<<" KB, "<<1000*clock()/CLOCKS_PER_SEC<<" ms\n";
    return 0;
}
/*
5
10 23 24 27 31
*/